
package com.ffcs.crmd.tsp.admin.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.utils.bean.BeanUtils;
import com.ffcs.crmd.platform.core.ddd.facade.impl.AbstractCrmDomFacade;
import com.ffcs.crmd.tsp.admin.api.dto.JobDTO;
import com.ffcs.crmd.tsp.admin.api.facade.IJobFacade;
import com.ffcs.crmd.tsp.admin.entity.Job;
import com.ffcs.crmd.tsp.admin.service.IJobService;

@Service("jobFacade")
public class JobFacadeImpl extends AbstractCrmDomFacade implements IJobFacade {
    
    @Autowired
    private IJobService jobService;
    
    private PageInfo<JobDTO> copyPageInfo(PageInfo<Job> pageInfo) throws Exception {
        PageInfo<JobDTO> pageInfoDto = new PageInfo<JobDTO>();
        BeanUtils.applyIf(pageInfoDto, pageInfo, false);
        pageInfoDto.setList(BeanUtils.copyList(pageInfo.getList(), JobDTO.class));
        return pageInfoDto;
    }
    
    @Override
    public void deleteJobdetailList(List<JobDTO> jobDTOList) throws Exception {
        for (JobDTO jobDTO : jobDTOList) {
            Job job = new Job();
            BeanUtils.applyIf(job, jobDTO, false);
            jobService.deleteJobDetail(job);
        }
    }
    
    @Override
    public JobDTO get(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        
        Job Rjob = jobService.get(job);
        JobDTO rjobDTO = new JobDTO();
        BeanUtils.applyIf(rjobDTO, Rjob, false);
        return rjobDTO;
    }
    
    @Override
    public void pause(List<JobDTO> jobDTOList) throws Exception {
        List<Job> jobList = BeanUtils.copyList(jobDTOList, Job.class);
        jobService.pauseJob(jobList);
    }
    
    @Override
    public List<JobDTO> query(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        
        List<Job> sliceList = jobService.query(job);
        return BeanUtils.copyList(sliceList, JobDTO.class);
    }
    
    @Override
    public PageInfo<JobDTO> queryPage(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        
        PageInfo<Job> pageInfo = jobService.queryPage(job, jobDto.getPageNumber(), jobDto.getPageSize());
        return copyPageInfo(pageInfo);
    }
    
    @Override
    public void remove(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        jobService.deleteJob(job);
    }
    
    @Override
    public void remove(List<JobDTO> jobDtoList) throws Exception {
        List<Job> jobList = BeanUtils.copyList(jobDtoList, Job.class);
        jobService.deleteJob(jobList);
    }
    
    @Override
    public void resume(List<JobDTO> jobDtoList) throws Exception {
        List<Job> jobList = BeanUtils.copyList(jobDtoList, Job.class);
        jobService.resumeJob(jobList);
    }
    
    @Override
    public void save(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        jobService.saveJob(job);
    }
    
    @Override
    public void update(JobDTO jobDto) throws Exception {
        Job job = new Job();
        BeanUtils.applyIf(job, jobDto, false);
        jobService.updateJob(job);
    }
    
}
